package com.langxin.site.action;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.langxin.site.biz.ProductBiz;
import com.langxin.site.model.ProductInfo;

/**
 * 产品
 * @author guqj
 *
 */
@Controller
@RequestMapping("chanpin")
public class ProductAction {

	@Autowired
	private ProductBiz   productBiz;
	
	/**
	 * 分组列表
	 * @return
	 */
	@RequestMapping(value = "", method = RequestMethod.GET)
	public String prod(Model model){
		model.addAttribute("products", productBiz.queryGroupList());
		model.addAttribute("gifts", productBiz.queryGifts(4));
		return "prod/prod_list.jsp";
	}
	
	/**
	 * 旅游详情
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "{id}", method = RequestMethod.GET)
	public String prodDetail(Model model, @PathVariable Integer id){
		ProductInfo productInfo = productBiz.queryById(id);
		if(productInfo == null){
			return "error/404.jsp";
		}
		model.addAttribute("gifts", productBiz.queryGifts(4));
		model.addAttribute("productInfo", productInfo);
		return "prod/prod_detail.jsp";
	}
}
